package com.lrs.s2sh.web.action;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.beans.factory.annotation.Autowired;

import com.lrs.s2sh.service.FlexiblePageService;
import com.lrs.s2sh.web.jsonUtils.DateJsonValueProcessor;
import com.lrs.s2sh.web.jsonUtils.MixBean;
import com.lrs.s2sh.web.jsonUtils.MixJsonValueProcessor;
import com.lrs.s2sh.xsd.wrapper.EEPageCfgWrapper;
import com.opensymphony.xwork2.ActionSupport;

public class JGridAction extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	
	private EEPageCfgWrapper wrapper;
	
	@Autowired
	private FlexiblePageService flexibleService;
	
	public String showFlexEE() throws Exception {
		
		wrapper = flexibleService.getEECustomizedWrapper();
		
		System.out.println("wrapper id = " + wrapper.getId());
		
		wrapper.getJqGridCfg().setUrl("jqGrid/ee_real_world/newData.json");
		
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
		jsonConfig.registerJsonValueProcessor(MixBean.class, new MixJsonValueProcessor());
		
		System.out.println(JSONObject.fromObject(wrapper.getJqGridCfg(), jsonConfig));
		
//		request.setAttribute("jqCfg", JSONObject.fromObject(wrapper.getJqGridCfg(), jsonConfig));
//		request.setAttribute("wrapper", wrapper);
		
		return SUCCESS;
		
	}
	
	public String input() throws Exception {
		
		return INPUT;
	}
	
}
